//
//  RootViewController.h
//  ProjectA_V0.1
//
//  Created by liuchang on 14/12/20.
//  Copyright (c) 2014年 liuchang. All rights reserved.
//

#import "DB.h"
#import <sqlite3.h>

static sqlite3 * dbPoint = nil;

@implementation DB

+ (sqlite3 *)openDB
{
    if (dbPoint) {
        return dbPoint;
    }
    else {
        NSFileManager * manager = [NSFileManager defaultManager];
        NSArray * pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString * path = [pathArr firstObject];
        path = [NSString stringWithFormat:@"%@/%@", path, @"LazyClock.rdb"];
        if (![manager fileExistsAtPath:path]) {
            NSString * source = [[NSBundle mainBundle] pathForResource:@"LazyClock" ofType:@"rdb"];
            [manager copyItemAtPath:source toPath:path error:nil];
        }
        sqlite3_open([path UTF8String], &dbPoint);
        return dbPoint;
    }
}

@end
